<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
	
    <h:body>
		<ui:composition template="/admin/template.xhtml">		    			
		<p:panel header="Zápasy">	
			<h:panelGrid columns="2">
				<p:panel header="Administrace zápasů" style="min-width:500px;min-height: 1129px;">
					<h:panelGrid columns="1">	
							<p:panel header="Výběr Soutěže" style="min-width:500px;">	
							<h:form>	
								<h:panelGrid columns="2">
									<h:panelGroup>
										<h:outputText value="Sezóna : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="seasonSelect" value="#{matchBean.selectedSeasonName}" style="width: 150px" >  
							                <f:selectItem  itemLabel="Vyberte sezónu" itemValue="" />  
							                <f:selectItems value="#{matchBean.seasonNamesList}" />
							                <p:ajax  update="teamSelect" listener="#{matchBean.handleSeasonChange}" /> 
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="Soutěž : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="teamSelect" value="#{matchBean.selectedCompetionName}" style="width: 150px" >  
							                <f:selectItem itemLabel="Vyberte soutěž" itemValue="" />  
							                <f:selectItems value="#{matchBean.competionNameList}" />
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup>            			
			            				<p:commandButton value="Hledej"  actionListener="#{matchBean.fillMatchList}" action="matches.xhtml?faces-redirect=true" update=":detailSouteze,:addCompetionForm,:growl,:delegatDialog"/>
			            			<h:panelGroup>
			            			</h:panelGroup>
			            		</h:panelGrid>
			            	</h:form>		
		            		</p:panel>
		            		<p:panel>            			
	            				<h:form id="detailSouteze" >
									<p:dataTable id="playerTable" sortBy="#{player.round}" var="player" value="#{matchBean.matchList}" rowKey="#{player.id}"  selection="#{matchBean.selectedMatch}" emptyMessage="Žádné zápasy nenalezeny" selectionMode="single" tableStyle="min-width:300px;" paginatorAlwaysVisible="false" paginatorPosition="bottom"  paginator="true" rows="15">
								        <f:facet name="header">
											<h:outputText value="Seznam zápasů v soutěži"/>											
								        </f:facet>
								        <p:column headerText="Kolo" sortBy="#{player.round}" >  
								            <h:outputText value="#{player.round}" />  
								        </p:column>
								        <p:column headerText="Kod" sortBy="#{player.matchCode}" >  
								            <h:outputText value="#{player.matchCode}" />  
								        </p:column>
								        <p:column headerText="Datum:" sortBy="#{player.datum}" >  
								            <h:outputText value="#{player.datum}" />  
								        </p:column>
								        <p:column headerText="Čas:" >  
								            <h:outputText value="#{player.start}" />  
								        </p:column>
								        <p:column headerText="Domácí" >  
								            <h:outputText value="#{player.homeTeam.name}" />  
								        </p:column>
								        <p:column>  
								            <h:outputText value="#{player.homeTeamScore}" />  
								        </p:column>
								        <p:column>  
								            <h:outputText value="#{player.awayTeamScore}" />  
								        </p:column>
								        <p:column headerText="Hosté" >  
								            <h:outputText value="#{player.awayTeam.name}" />  
								        </p:column>
								        <f:facet name="footer">  
							                <c:if test="#{matchBean.selectedSeasonName != '' and matchBean.selectedCompetionName != ''}">
							              		  <p:commandButton  icon="ui-icon-document" value="přidat zápas"  update=":form:" oncomplete="competionAddDialog.show()"/>
							              		  <p:commandButton  icon="ui-icon-document" value="smazat" onclick="deleteConfirmation.show()"/>
							         	     	  <p:commandButton  icon="ui-icon-document" value="upravit"  update=":form,:matchDetailDialog" oncomplete="DetailDialog.show()"/>           
					       						  <p:commandButton  icon="ui-icon-document" value="Vyplnit podle BT (8)" actionListener="#{matchBean.fillBergerEight}" oncomplete="dialogBergerTabs.show()"/>
					       						  <p:commandButton  icon="ui-icon-document" value="Vyplnit podle BT (14)" actionListener="#{matchBean.fillBergerFourteen}" oncomplete="dialogBergerTabs.show()"/>
					       						  <p:commandButton  icon="ui-icon-document" value="Vyplnit podle BT (16)" actionListener="#{matchBean.fillBergerSixteen}" oncomplete="dialogBergerTabs.show()"/>
					       					</c:if>
					       				</f:facet> 
						  	        </p:dataTable>
						  	        <p:confirmDialog id="confirmDialog" message="Opravdu chcete smazat tým?" header="Potvrzení smazání" severity="alert" widgetVar="deleteConfirmation" position="10,10">  	                  
						      		   	<p:commandButton id="confirm" value="Ano" update="detailSouteze,:growl,:form,:matchDetailDialog,:events" onclick="deleteConfirmation.hide()" actionListener="#{matchBean.deleteMatch}" />  
						  		    	<p:commandButton id="decline" value="Ne" onclick="deleteConfirmation.hide()"/>   	                  
				  			 		</p:confirmDialog>  
					  	        </h:form>
					  	        <p:dialog id="matchDetailDialog" header="Detail zápasu" widgetVar="DetailDialog" resizable="false" showEffect="clip" hideEffect="fold" position="10,10" height="300">
									<h:form>
											<h:panelGroup columns="4" cellpadding="4">
									        	<h:outputText value="KONEČNÉ SKORE: #{matchBean.selectedMatch.homeTeam.name}" /><h:outputText value="  " />
								        	 	<h:inputText value="#{matchBean.selectedMatch.homeTeamScore}" style="width:20px" />
								        	 	<h:outputText value=" : " />
								        	 	<h:inputText value="#{matchBean.selectedMatch.awayTeamScore}" style="width:20px"/><h:outputText value="  " />
								        	 	<h:outputText value="#{matchBean.selectedMatch.awayTeam.name}" />	
								
									        	
								        	</h:panelGroup>		
											<h:panelGrid columns="8" cellpadding="4">   
								        	 		<h:outputText value="Kód : " />
								        	 		<h:inputText value="#{matchBean.selectedMatch.matchCode}" style="width:60px" />
								        	 		<h:outputText value="Kolo : " />
								        	 		<h:inputText value="#{matchBean.selectedMatch.round}" style="width:20px"/>
								        	 		<h:outputText value="Datum : " />
								        	 		<p:inputMask value="#{matchBean.selectedMatch.datum}" mask="99.99.9999" style="width:70px"/>
								        	 		<h:outputText value="Čas : " />
								        	 		<p:inputMask value="#{matchBean.selectedMatch.start}" mask="99:99" style="width:50px"/>
								        	 		<h:outputText value="Počet diváků : " />
								        	 		<h:inputText value="#{matchBean.selectedMatch.pocetHracu}" style="width:100px" />
										     </h:panelGrid>									     		
								        	 <h:panelGrid columns="4" cellpadding="4">        	 		
								        	 		<h:outputText value="Delegát:" />
								        	 		<h:inputText value="#{matchBean.selectedMatch.delegat}" />
								        	 		<h:outputText value="Spolujízda:" />
								        	 		<h:inputText value="#{matchBean.selectedMatch.spolujizda}" />
								        	 		<h:outputText value="Hlavní rozhodčí:" />
								        	 		<h:inputText value="#{matchBean.selectedMatch.mainReferee}" />
								        	 		<h:outputText value="AR1:" />
								        	 		<h:inputText value="#{matchBean.selectedMatch.lineReferee}" />	
								        	 		<h:outputText value="AR2:" />
								        	 		<h:inputText value="#{matchBean.selectedMatch.lineRefereeTwo}" />		 
								        	 </h:panelGrid>	
							        	 <h:panelGrid columns="2" cellpadding="4">
							        	  	<p:panel header="Události : #{matchBean.selectedMatch.homeTeam.name}" >
							        	  		 <h:panelGrid columns="2" cellpadding="4">
								        	  		<h:outputText value="Góly:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.domaciStrelci}" style="width:150px" maxheight="80" autoResize="false"/> 
								        	  		<h:outputText value="Základní sestava:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.domaciZaklSestava}" style="width:150px" maxheight="100" autoResize="false" />
								        	  		<h:outputText value="Žluté karty:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.domaciZluteKarty}" style="width:150px" maxheight="40" autoResize="false"/>
								        	  		<h:outputText value="Červené karty:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.domaciCerveneKarty}" style="width:150px" maxheight="30" autoResize="false"/>
							        	  			<h:outputText value="Jméno, funkce:" />
				       	  							<p:inputText value="#{matchBean.selectedMatch.domaciJmeno}" style="width:150px"  maxheight="30" autoResize="false"/>
				       	  							<h:outputText value="Komentář:" />
							        	  			<p:inputTextarea value="#{matchBean.selectedMatch.domaciKomentar}" style="width:150px"  maxheight="30" autoResize="false"/>
							        	  		</h:panelGrid>
							        	  	</p:panel>
							        	  	<p:panel header="Události : #{matchBean.selectedMatch.awayTeam.name}" >
							        	  		 <h:panelGrid columns="2" cellpadding="4">
								        	  		<h:outputText value="Góly:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.hosteStrelci}" style="width:150px" maxheight="80" autoResize="false"/> 
								        	  		<h:outputText value="Základní sestava:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.hosteZaklSestava}" style="width:150px" maxheight="100" autoResize="false" />
								        	  		<h:outputText value="Žluté karty:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.hosteZluteKarty}" style="width:150px" maxheight="40" autoResize="false"/>
								        	  		<h:outputText value="Červené karty:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.hosteCerveneKarty}" style="width:150px" maxheight="30" autoResize="false"/>
								        	  		<h:outputText value="Jméno, funkce:" />
				       	  							<p:inputText value="#{matchBean.selectedMatch.hosteJmeno}" style="width:150px"  maxheight="30" autoResize="false"/>
				       	  							<h:outputText value="Komentář:" />
								        	  		<p:inputTextarea value="#{matchBean.selectedMatch.hosteKomentar}" style="width:150px" maxheight="40" autoResize="false"/>
							        	  		</h:panelGrid>							        	  	
							        	  	</p:panel>
							        	 </h:panelGrid>
							        	 <p:commandButton value="Uložit změny" actionListener="#{matchBean.updateMatch}" update=":detailSouteze,:growl,:addCompetionForm,:matchDetailDialog" oncomplete="DetailDialog.hide()"/>								
									</h:form>  
								</p:dialog>
					  	        <p:dialog id="dialogAddCompetion" header="Přidat zápas do soutěže" widgetVar="competionAddDialog" resizable="false" width="300" showEffect="clip" hideEffect="fold" position="10,10">  
							      	 <h:form id="addCompetionForm">   
							      	    <h:panelGrid columns="2" cellpadding="4">
												<h:outputText value="Domácí: " />
												<h:panelGroup>													
													<p:selectOneMenu value="#{matchBean.selectedHomeTeamName}" style="width: 150px" >  
										                <f:selectItem  itemLabel="Vyberte domácí tým" itemValue="" />  
										                <f:selectItems value="#{matchBean.teamNameList}" />
							            			</p:selectOneMenu>			            			 
						            			</h:panelGroup>
						            			<h:outputText value="Hosté: " />
												<h:panelGroup>													
													<p:selectOneMenu value="#{matchBean.selectedAwayTeamName}" style="width: 150px" >  
										                <f:selectItem  itemLabel="Vyberte dostující tým" itemValue="" />  
										                <f:selectItems value="#{matchBean.teamNameList}" />
							            			</p:selectOneMenu>			            			 
						            			</h:panelGroup>
						            			<h:outputText value="Kolo: " />	
						            			<h:inputText value="#{matchBean.round}" style="width: 20px"/>			
						            			<h:outputText value="Datum: " />	
						            			<p:inputMask value="#{matchBean.matchDatum}" mask="99.99.9999" style="width: 70px"/>	
						            			<h:outputText value="Čas: " />	
						            			<p:inputMask value="#{matchBean.matchStart}" mask="99:99" style="width: 50px"/>
						            			<h:outputText value="Kód zápasu: " />	
						            			<h:inputText value="#{matchBean.matchCode}" style="width:60px"/>			            						 
										        <p:commandButton value="Přidat" actionListener="#{matchBean.addMatchToCompetion}" update=":detailSouteze,:growl,:addCompetionForm" oncomplete="competionAddDialog.hide()"/>    
							        	</h:panelGrid>
							         </h:form>	
								</p:dialog>
								<p:dialog id="dialogBergerTabs" header="Bergerova tabulka" widgetVar="dialogBergerTabs" resizable="false" width="500" showEffect="clip" hideEffect="fold" position="10,10">  
							      	 <h:form id="dialogBergerTabsForm">
							      	    <h:panelGrid columns="6" cellpadding="2">
								        	  		<h:outputText value="Kolo:" />
								        	  		<p:inputText value="#{matchBean.roundOne}" style="width: 20px"/>
								        	  		<h:outputText value="Datum:" />
								        	  		<p:inputMask value="#{matchBean.dateOne}" mask="99.99.9999" style="width: 70px"/>
								        	  		<h:outputText value="Time:" />
								        	  		<p:inputMask value="#{matchBean.timeOne}" mask="99:99" style="width: 40px"/>
								        	  		
								        	  		<h:outputText value="Kolo:" />
								        	  		<p:inputText value="#{matchBean.roundTwo}" style="width: 20px"/>
								        	  		<h:outputText value="Datum:" />
								        	  		<p:inputMask value="#{matchBean.dateTwo}" mask="99.99.9999" style="width: 70px"/>
								        	  		<h:outputText value="Time:" />
								        	  		<p:inputMask value="#{matchBean.timeTwo}" mask="99:99" style="width: 40px"/>
								        	  		
								        	  		<h:outputText value="Kolo:" />
								        	  		<p:inputText value="#{matchBean.roundThree}" style="width: 20px"/>
								        	  		<h:outputText value="Datum:" />
								        	  		<p:inputMask value="#{matchBean.dateThree}" mask="99.99.9999" style="width: 70px"/>
								        	  		<h:outputText value="Time:" />
								        	  		<p:inputMask value="#{matchBean.timeThree}" mask="99:99" style="width: 40px"/>
								        	  		
								        	  		<h:outputText value="Kolo:" />
								        	  		<p:inputText value="#{matchBean.roundFour}" style="width: 20px"/>
								        	  		<h:outputText value="Datum:" />
								        	  		<p:inputMask value="#{matchBean.dateFour}" mask="99.99.9999" style="width: 70px"/>
								        	  		<h:outputText value="Time:" />
								        	  		<p:inputMask value="#{matchBean.timeFour}" mask="99:99" style="width: 40px"/>
								        	  		
								        	  		<h:outputText value="Kolo:" />
								        	  		<p:inputText value="#{matchBean.roundFive}" style="width: 20px"/>
								        	  		<h:outputText value="Datum:" />
								        	  		<p:inputMask value="#{matchBean.dateFive}" mask="99.99.9999" style="width: 70px"/>
								        	  		<h:outputText value="Time:" />
								        	  		<p:inputMask value="#{matchBean.timeFive}" mask="99:99" style="width: 40px"/>
								        	  		
								        	  		<h:outputText value="Kod:" />
								        	  		<p:inputText value="#{matchBean.code}" style="width: 30px"/>
							        	</h:panelGrid>   
							      	    <h:panelGrid columns="2" cellpadding="4">
							      	    		<p:commandButton  icon="ui-icon-document" value="vyplnit" actionListener="#{matchBean.bergerTabSixteen}" update=":detailSouteze,:dialogBergerTabsForm" oncomplete="dialogBergerTabs.hide()">
												</p:commandButton>
							        	</h:panelGrid>
							         </h:form>	
								</p:dialog>						 					  	                   		    
							</p:panel>  	  
					</h:panelGrid>
				</p:panel>
			</h:panelGrid>
		</p:panel>			
		</ui:composition>	
	</h:body>
</html>